//
//  Utils.swift
//  SQliteData
//
//  Created by Henry LIU on 16/12/2014.
//  Copyright (c) 2014 Henry LIU. All rights reserved.
//

import UIKit

class Utils: NSObject {
    class func getPath(fileName: String) -> String {
        return NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0].stringByAppendingPathComponent(fileName);
    }
    
    class func copyFile(fileName: NSString){
        var dbPath: String = getPath(fileName)
        println("dbpath:\(dbPath)")
        var fileManager = NSFileManager.defaultManager()
        if !fileManager.fileExistsAtPath(dbPath){
            var fromPath: String? = NSBundle.mainBundle().resourcePath?.stringByAppendingPathComponent(fileName)
            println("fromPath:\(fromPath)")
            fileManager.copyItemAtPath(fromPath!, toPath: dbPath, error: nil)
        }
    }
    
    class func invokeAlertMethod(strTitle: NSString, strBody: NSString, delegate:AnyObject?){
        var alert: UIAlertView = UIAlertView()
        alert.message = strBody;
        alert.title = strTitle
        alert.delegate = delegate
        alert.addButtonWithTitle("OK")
        alert.show()
    }
}
